package indi.gtl.superbrain.models;

import android.graphics.Bitmap;

import indi.gtl.superbrain.widget.CircleChart;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin1 on 15-5-29.
 */
public class UserInfo implements Constant, Serializable {
    private static final String[] titles = {"观察力", "计算力", "反应力", "判断力", "正确率", "记忆力"};

    public String name;     // 用户名
    public int head;        // 头像
    public String imei;     // 手机序列号
    public String psw;      // 登录密码

    public int speed;       // 反应力
    public int memory;      // 记忆力
    public int accuracy;    // 正确率
    public int judgement;   // 判断力
    public int calculation; // 计算力
    public int observation; // 观察力

    public int sum_score;   // 总得分

    public void setValue(
            String name,
            int head,
            String imei,
            String psw,
            int speed,
            int memory,
            int accuracy,
            int judgement,
            int calculation,
            int observation,
            int sum_score){

        this.name = name;
        this.head = head;
        this.imei = imei;
        this.psw = psw;
        this.speed = speed;
        this.memory = memory;
        this.accuracy = accuracy;
        this.judgement = judgement;
        this.calculation = calculation;
        this.observation = observation;
        this.sum_score = sum_score;
    }

    public static UserInfo parse(String info){
        JSONObject jsonObject;
        try {
            jsonObject = new JSONObject(info);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }

        UserInfo userInfo = new UserInfo();
        userInfo.name = jsonObject.optString("name");
        userInfo.head = jsonObject.optInt("head");
        userInfo.imei = jsonObject.optString("imei");
        userInfo.psw = jsonObject.optString("psw");
        userInfo.speed = jsonObject.optInt("speed");
        userInfo.memory = jsonObject.optInt("memory");
        userInfo.accuracy = jsonObject.optInt("accuracy");
        userInfo.judgement = jsonObject.optInt("judgement");
        userInfo.calculation = jsonObject.optInt("calculation");
        userInfo.observation = jsonObject.optInt("observation");
        userInfo.sum_score = jsonObject.optInt("sum_score");

        return userInfo;
    };

    public int getHeadImage(){
        return headList[head % headList.length];
    }

    @Override
    public String toString() {
        JSONObject jsonObject = new JSONObject();
        try {
            jsonObject.put("name", name);
            jsonObject.put("head", head);
            jsonObject.put("imei", imei);
            jsonObject.put("psw", psw);
            jsonObject.put("speed", speed);
            jsonObject.put("memory", memory);
            jsonObject.put("accuracy", accuracy);
            jsonObject.put("judgement", judgement);
            jsonObject.put("calculation", calculation);
            jsonObject.put("observation", observation);
            jsonObject.put("sum_score", sum_score);
        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
        return jsonObject.toString();
    }

    public static String[] getTitles(){
        return titles;
    }

    public List<CircleChart.Info> getInfoList(){
        List<CircleChart.Info> mInfoList = new ArrayList<CircleChart.Info>();
        mInfoList.add(new CircleChart.Info(100, observation));
        mInfoList.add(new CircleChart.Info(100, calculation));
        mInfoList.add(new CircleChart.Info(100, speed));
        mInfoList.add(new CircleChart.Info(100, judgement));
        mInfoList.add(new CircleChart.Info(100, accuracy));
        mInfoList.add(new CircleChart.Info(100, memory));

        return mInfoList;
    }
}